package day05;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class Demo08 {
    public static void main(String[] args) throws InterruptedException {
        /*
         * 阻塞队列
         */
        BlockingQueue<String> queue = new LinkedBlockingQueue<>(4);
        queue.put("Tom");
        queue.put("Jerry");
        queue.put("Andy");
        queue.put("Lee");
        System.out.println(queue);
        Thread t1 = new Thread(){
            @Override
            public void run() {
                try {
                    queue.put("HI");
                    System.out.println("添加成功:"+queue);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    System.out.println("被打断");
                }
            }
        };
        t1.start();
        Thread.sleep(2000);
        String str = queue.take();
        System.out.println(str);
        System.out.println(queue);
    }
}
